
import 'package:flutter_clx_base/api/base_dio.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';

import '../routes/route_names.dart';
import '../utils/sp_util.dart';
import 'api_config.dart';
import 'header_interceptor.dart';

class DioUtils extends BaseDio {
  static final DioUtils _singleton = DioUtils._internal();

  static DioUtils get instance => _singleton;

  DioUtils._internal();

  @override
  Interceptor getHeadersInterceptor() {
    return HeaderInterceptor();
  }

  @override
  void onLoginExpire() {
    // token 失效
    ToastUtil.showToast("登录失效，请重新登录");
    logoutRemove();
    Get.offAllNamed(AppRoutes.loginPage);
  }

  @override
  String setBaseUrl() {
    return ApiConfig.apiHost;
  }

  @override
  bool isProdEnv() => ApiConfig.apiHost == ApiConfig.prod; // 生产环境不设置代理
}
